<template>
<div>
  <table>
    <tr>
      <td>名称</td>
      <td>价钱</td>
      <td>销量</td>
      <td></td>
    </tr>
    <tr v-for="i in shop">
      <td>{{i.name}}</td>
      <td>{{i.price}}</td>
      <td>{{i.xiaol}}</td>
      <td>
        <button @click="pay(i.id)">购买</button></td>
    </tr>
  </table>
</div>
</template>

<script>
export default {
  name: "show_shop",
  data(){
  return{
  shop:[],
  userid:localStorage.getItem('userid')
  }
  },
  methods:{
  get_shop(){
  this.$axios.get('/login/shop')
  .then(res=>{
  if(res.data.code==200){
  this.shop = res.data.list
  }
  })
  },
  pay(id){
  if(this.userid){
  this.$axios.post('/login/shop',{'userid':this.userid,'id':id})
  .then()
  }
  else {
  this.$router.push('/login')
  }

  }
  },
  mounted() {
  this.get_shop()
  }
}
</script>

<style scoped>

</style>
